package com.huanshi.module.ums.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huanshi.common.CommonResult;

import com.huanshi.service.UmsRoleService;
import com.huanshi.entity.UmsRole;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author 幻世
 * @since 2023-09-13
 */
@RestController
@RequestMapping("/api/role")
public class UmsRoleController {

    @Resource
    private UmsRoleService roleService;

    // 新增或者更新
    @PostMapping
    public CommonResult save(@RequestBody UmsRole role) {
        return CommonResult.success(roleService.saveOrUpdate(role));
    }

    @DeleteMapping("/{id}")
    public CommonResult delete(@PathVariable Integer id) {
        return CommonResult.success(roleService.removeById(id));
    }

    @PostMapping("/del/batch")
    public CommonResult deleteBatch(@RequestBody List<Integer> ids) {
        return CommonResult.success(roleService.removeByIds(ids));
    }

    @GetMapping
    public CommonResult findAll() {
        return CommonResult.success(roleService.list());
    }

    @GetMapping("/{id}")
    public CommonResult findOne(@PathVariable Integer id) {
        return CommonResult.success(roleService.getById(id));
    }

    @GetMapping("/page")
    public CommonResult findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize) {
        QueryWrapper<UmsRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return CommonResult.success(roleService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}

